﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin
{
    public partial class PriceAdjustPlanUpdate : BasePage
    {
        private IBLL_ProcurementBasic ibp = Factory.BLL_ProcurementBasic();
        public PriceAdjustPlanUpdate()
        {
            this.ModuleNo = Module.调价计划列表.ToString();
            this.PageOperateType = OperateType.调价计划列表.ToString();
        }
        private string PricePlanSerialID = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            //绑定需要修改的调价计划的信息
            if (!IsPostBack)
            {
                //
                PricePlanSerialID = Request.QueryString["PricePlanSerialID"];
                if (string.IsNullOrEmpty(PricePlanSerialID))
                {
                    PageError("参数错误！", this.ReturnUrl);
                }
                int inttmp;
                IList<Model.View.AdjustPricePlan> AdjustPricePlanList = ibp.GetAdjustPricePlanByWhere(new HZ.DrugTrade.Model.Query.AdjustPricePlan() { PricePlanSerialID = PricePlanSerialID, SortFields = "ProcureCatalogID" }, 1, 0, out inttmp);
                txtCompany_SC.Text = AdjustPricePlanList[0].CompanyName_SC;
                txtCompany_TB.Text = AdjustPricePlanList[0].CompanyName_TB;
                txtGoodsName.Text = AdjustPricePlanList[0].GoodsName;
                txtMaterial.Text = AdjustPricePlanList[0].Material;
                txtOutLook.Text = AdjustPricePlanList[0].Outlookc;
                //txtPack.Text = AdjustPricePlanList[0].Pack;
                txtProcurePrice.Text = AdjustPricePlanList[0].ProcurePrice.ToString();
                txtGoodsName.Text = AdjustPricePlanList[0].GoodsName;
                txtUnit.Text = AdjustPricePlanList[0].Unit;
                txtAdjustPrice.Text = AdjustPricePlanList[0].AdjustPrice.ToString();
                txtAdjustPriceReason.Text = AdjustPricePlanList[0].AdjustPriceReason;
                txtExecuteStartTime.Text = string.Format("{0:yyyy-MM-dd HH:mm:ss}", AdjustPricePlanList[0].ExecuteStartTime);
                txtPlanTime.Text =string.Format("{0:d}",AdjustPricePlanList[0].PlanTime) ;

                //添加属性
                txtExecuteStartTime.Attributes.Add("onFocus", "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false,readOnly:true,minDate:'" + DateTime.Now.AddHours(0.5).ToString("yyyy-MM-dd HH:mm:ss") + "'})");


            }
        }

        /// <summary>
        /// 修改调价计划
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
           
            if (Page.IsValid)
            {
                //获取修改的信息
                AdjustPricePlan adjustpriceplan = new AdjustPricePlan();
                adjustpriceplan.PricePlanSerialID = Request.QueryString["PricePlanSerialID"];
                adjustpriceplan.ProcureCatalogID = Request.QueryString["ProcureCatalogID"];
                adjustpriceplan.PlanTime = new HZ.Common.ConvertHelper(txtPlanTime.Text).ToDateTime;
                adjustpriceplan.PlanPerson = CurrentAccount.GetUser().UserID ;
                adjustpriceplan.ExecuteStartTime = new HZ.Common.ConvertHelper(txtExecuteStartTime.Text.Trim()).ToDateTime;
                adjustpriceplan.AdjustPriceReason = txtAdjustPriceReason.Text;
                adjustpriceplan.OriginalPrice = new HZ.Common.ConvertHelper(txtProcurePrice.Text.Trim()).ToDecimal;
                adjustpriceplan.AdjustPrice = new HZ.Common.ConvertHelper(txtAdjustPrice.Text.Trim()).ToDecimal;
                adjustpriceplan.ExecuteState = 0;

                //执行方法
                if (ibp.UpdateAdjustPricePlan(adjustpriceplan) == 1)
                {
                    PageInfo("修改成功！", this.ReturnUrl);
                }
                else
                {
                    PageError("修改失败！", "");
                }
            }
        }
    }
}
